# by disKret
import sys
from com.l2jserver.gameserver.model.quest import State
from com.l2jserver.gameserver.model.quest import QuestState
from com.l2jserver.gameserver.model.quest.jython import QuestJython as JQuest

qn = "31_SecretBuriedInTheSwamp"

# NPC
ABERCROMBIE = 31555
FORGOTTEN_MONUMENT_1,FORGOTTEN_MONUMENT_2,FORGOTTEN_MONUMENT_3,FORGOTTEN_MONUMENT_4,CORPSE_OF_DWARF = range(31661,31666)
# ITEMS
KRORINS_JOURNAL = 7252

class Quest (JQuest) :

	def __init__(self,id,name,descr):
		JQuest.__init__(self,id,name,descr)
		self.questItemIds = [KRORINS_JOURNAL]

	def onAdvEvent (self,event,npc, player) :
		htmltext = event
		st = player.getQuestState(qn)
		if not st : return
		if event == "31555-1.htm" :
			st.set("cond","1")
			st.setState(State.STARTED)
			st.playSound("ItemSound.quest_accept")
		elif event == "31665-1.htm" :
			st.set("cond","2")
			st.playSound("ItemSound.quest_itemget")
			st.giveItems(KRORINS_JOURNAL,1)
		elif event == "31555-4.htm" :
			st.set("cond","3")
			st.playSound("ItemSound.quest_middle")
		elif event == "31661-1.htm" :
			st.set("cond","4")
			st.playSound("ItemSound.quest_middle")
		elif event == "31662-1.htm" :
			st.set("cond","5")
			st.playSound("ItemSound.quest_middle")
		elif event == "31663-1.htm" :
			st.set("cond","6")
			st.playSound("ItemSound.quest_middle")
		elif event == "31664-1.htm" :
			st.set("cond","7")
			st.playSound("ItemSound.quest_middle")
		elif event == "31555-7.htm" :
			st.takeItems(KRORINS_JOURNAL,-1)
			st.addExpAndSp(490000,45880)
			st.giveItems(57,120000)
			st.unset("cond")
			st.exitQuest(False)
			st.playSound("ItemSound.quest_finish")
		elif event != "31663-0a.htm":
			htmltext = "<html><body>目前没有执行任务，或条件不符。</body></html>"
		return htmltext

	def onTalk (self,npc,player):
		htmltext = "<html><body>目前没有执行任务，或条件不符。</body></html>"
		st = player.getQuestState(qn)
		if not st : return htmltext

		npcId = npc.getNpcId()
		id = st.getState()
		cond = st.getInt("cond")

		if id == State.COMPLETED :
			htmltext = "<html><body>这是已经完成的任务。</body></html>"
		elif id == State.CREATED :
			if npcId == ABERCROMBIE and cond == 0 :
				if player.getLevel() >= 66 :
					htmltext = "31555-0.htm"
				else :
					htmltext = "31555-0a.htm"
					st.exitQuest(1)
		elif id == State.STARTED :
			if npcId == ABERCROMBIE :
				if cond == 1 :
					htmltext = "31555-2.htm"
				elif cond == 2 :
					htmltext = "31555-3.htm"
				elif cond == 3 :
					htmltext = "31555-5.htm"
				elif cond == 7 :
					htmltext = "31555-6.htm"
			elif npcId == CORPSE_OF_DWARF :
				if cond == 1 :
					htmltext = "31665-0.htm"
				elif cond == 2 :
					htmltext = "31665-2.htm"
			elif npcId == FORGOTTEN_MONUMENT_1 :
				if cond == 3 :
					htmltext = "31661-0.htm"
				elif cond > 3 :
					htmltext = "31661-2.htm"
			elif npcId == FORGOTTEN_MONUMENT_2:
				if cond == 4 :
					htmltext = "31662-0.htm"
				elif cond > 4 :
					htmltext = "31662-2.htm"
			elif npcId == FORGOTTEN_MONUMENT_3 :
				if cond == 5 :
					htmltext = "31663-0.htm"
				elif cond > 5 :
					htmltext = "31663-2.htm"
			elif npcId == FORGOTTEN_MONUMENT_4 :
				if cond == 6 :
					htmltext = "31664-0.htm"
				elif cond > 6 :
					htmltext = "31664-2.htm"
		return htmltext

QUEST		= Quest(31,qn,"埋藏沼泽的秘密")

QUEST.addStartNpc(ABERCROMBIE)

QUEST.addTalkId(ABERCROMBIE)

for i in range(31661,31666):
	QUEST.addTalkId(i)